<template>
  <div class="login-setting">
    <el-form
      ref="userForm"
      :model="userInfo"
      label-width="120px"
      :rules="rules"
      style="margin-left: 120px; margin-top: 30px"
    >
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="userInfo.username" style="width:300px" />
      </el-form-item>

      <el-form-item label="密码:" prop="password">
        <el-input v-model="userInfo.password" type="password" style="width:300px" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="SaveEmployeeInfoFn">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserDetailById } from '@/api/user'

import { SaveEmployeeInfoAPI } from '@/api/employees'
export default {
  name: 'LoginSetting',
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUserDetailByIdFn()
  },
  methods: {
    // 更新用户信息
    SaveEmployeeInfoFn() {
      // 兜底验证
      this.$refs.userForm.validate(async valid => {
        if (!valid) return
        // 调接口
        const res = await SaveEmployeeInfoAPI(this.userInfo)
        this.$message.success(res.message)
      })
    },
    // 获取用户详细信息
    async getUserDetailByIdFn() {
      const res = await getUserDetailById(this.$route.query.id)
      this.userInfo = res.data
    }
  }
}
</script>

   <style lang="scss" scoped></style>

